package cn.com.godliu.gateway.filters;

import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.gateway.filter.GatewayFilter;
import org.springframework.cloud.gateway.filter.factory.AbstractGatewayFilterFactory;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 局部过滤器是作用于某一个路由上
 */
@Slf4j
//@Component
public class LocalGatewayFilterFactory extends AbstractGatewayFilterFactory<LocalGatewayFilterFactory.Config> {

    public LocalGatewayFilterFactory() {
        super(Config.class);
    }

    @Override
    public GatewayFilter apply(Config config) {

        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String time = simpleDateFormat.format(new Date());
        log.info("LocalGatewayFilterFactory：{}", time);

        return new LocalFilter();
    }

    public static class Config {

    }
}
